package org.tamal.spring;

import java.io.Serializable;
import java.util.List;

import org.tamal.persistence.User;


/**
 * This is the service or business interface.
 * @author Tamal Kanti Nath
 */
public interface Service {

    /**
     * Returns an entity from JPQL query with positional parameters.
     * @param <T> the Entity type
     * @param query the named HQL query
     * @param params the positional parameter values
     * @return an entity
     */
    <T> T findEntity(String query, Object... params);

    /**
     * Returns an entity from JPQL query with positional parameters.
     * @param <T> the Entity type
     * @param query the named HQL query
     * @param params the positional parameter values
     * @return a list of entities
     */
    <T> List<T> findEntities(String query, Object... params);

    /**
     * Returns an entity from JPQL query with named parameters.
     * @param <T> the Entity type
     * @param cls the result class type
     * @param query the named JPQL query
     * @param params the positional parameter values
     * @return an entity
     */
    <T> T findEntity(Class<T> cls, String query, Object... params);

    /**
     * Returns an entity from JPQL query with named parameters.
     * @param <T> the Entity type
     * @param cls the result class type
     * @param query the named JPQL query
     * @param params the positional parameter values
     * @return a list of entities
     */
    <T> List<T> findEntities(Class<T> cls, String query, Object... params);

    /**
     * Persist an entity.
     * @param entity the entity to persist
     */
    void persist(Serializable entity);

    /**
     * Merge an entity.
     * @param <T> the entity type
     * @param entity the entity to merge
     * @return the merged entity
     */
    <T> T merge(T entity);

    /**
     * Logs in a user.
     * @param user the user
     * @return error key
     */
    String login(User user);
}
